import { ObjCreate } from "../../../common/ObjCreate";
import { LoaderHelp } from "../../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../../resource/ResFileConst";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { SArenaCrossFinalBattle } from "../../../../../../Message/Public/SArenaCrossFinalBattle";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { Cache } from "../../../../cache/Cache";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { PlayerUtil } from "../../../common/util/PlayerUtil";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class FinalPlayerCell
    
    export  class FinalPlayerCell /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._btnPlayer = ObjCreate.createGButton("", 0, 0, 120, 20, this, "ButtonBlueStyle");
            this._btnPlayer.addEventListener(flash.events.MouseEvent.CLICK, this.onClickPlayer);
            this._bmpCareer = new Object /* flash.display.Bitmap */();
            this._bmpCareer.x = -3;
            this._bmpCareer.y = -22;
            this.addChild(this._bmpCareer);
            LoaderHelp.addResCallBack(ResFileConst.ArenaCrossCareer, this.onResCompl);
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._isResCompl = true;
            this.updateView();
            return;
        }

        /* internal  */onClickPlayer(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._finalBattle) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetArenaCrossPlayerInfo, this._finalBattle.entityId));
            }
            return;
        }

        public updateData(arg1: SArenaCrossFinalBattle): void
        {
            this._finalBattle = arg1;
            this.updateView();
            return;
        }

        protected updateView(): void
        {
            var loc1=0;
            if (this._isResCompl) 
            {
                if (this._finalBattle) 
                {
                    this._btnPlayer.label = this._finalBattle.name;
                    if (EntityUtil.toString(this._finalBattle.entityId) != EntityUtil.toString(Cache.instance.role.entityInfo.entityId)) 
                    {
                        this._btnPlayer.styleName = "ButtonBlueStyle";
                    }
                    else 
                    {
                        this._btnPlayer.styleName = "ButtonGreenStyle";
                    }
                    this._btnPlayer.toolTipData = HTMLUtil.addColor(PlayerUtil.getProxyAndNameByEntityIdAndName(this._finalBattle.entityId, this._finalBattle.name), "#FFFFFF");
                    loc1 = 0;
                    if (this._finalBattle.positions.length > 0) 
                    {
                        loc1 = this._finalBattle.positions[(this._finalBattle.positions.length - 1)];
                    }
                    this._btnPlayer.setStyle("textFormat", this.getTextFormatByPos(loc1));
                }
                else 
                {
                    this._btnPlayer.styleName = "ButtonBlueStyle";
                    this._btnPlayer.label = "";
                    this._btnPlayer.toolTipData = "";
                }
                this._btnPlayer.drawNow();
            }
            return;
        }

        /* internal  */getTextFormatByPos(arg1: int): Object /* flash.text.TextFormat */
        {
            if (arg1 >= 61) 
            {
                return GlobalStyle.textFormatOrange;
            }
            if (arg1 >= 57) 
            {
                return GlobalStyle.textFormatPurple;
            }
            if (arg1 >= 49) 
            {
                return GlobalStyle.textFormatBlue;
            }
            if (arg1 >= 33) 
            {
                return GlobalStyle.textFormatGreen;
            }
            return GlobalStyle.textFormatWhite;
        }

        /* internal */ /* var */_bmpCareer: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnPlayer: GButton;

        /* internal */ /* var */_isResCompl: Boolean=false;

        /* internal */ /* var */_finalBattle: SArenaCrossFinalBattle;
    }
